from time import sleep
from selenium import webdriver

# 打开进销存登录页面，登录
driver = webdriver.Firefox()
driver.get("http://localhost/lzj/index.asp")
driver.find_element_by_name('username').send_keys('admin')
driver.find_element_by_name('pwd').send_keys('admin')
driver.find_element_by_name('enter').click()
sleep(3)

#删除全部单位记录
driver.switch_to.frame('left')
sysset_css = '.menuall > tbody:nth-child(1) > tr:nth-child(13) > td:nth-child(1)'
driver.find_element_by_css_selector(sysset_css).click()
sleep(2)
danwei_css = '#g_6 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(7) > td:nth-child(1)'
driver.find_element_by_css_selector(danwei_css).click()
sleep(2)
driver.switch_to.default_content()
driver.switch_to.frame('right')
sleep(2)
bt_css = '#chkall'
driver.find_element_by_css_selector(bt_css).click()
sleep(2)
delete_css = 'input.button:nth-child(2)'
driver.find_element_by_css_selector(delete_css).click()
sleep(2)
driver.switch_to.alert.accept()
sleep(2)

#新增一条单位记录
driver.switch_to.default_content()
driver.switch_to.frame('right')
sleep(2)
insertdw_css = 'input.button:nth-child(1)'
driver.find_element_by_css_selector(insertdw_css).click()
sleep(2)
driver.find_element_by_name('danwei').send_keys('个')
driver.find_element_by_name('submit').click()
sleep(2)
driver.switch_to.alert.accept()
sleep(2)

#新增一个大类
driver.switch_to.default_content()
driver.switch_to.frame('left')
sysset_css2 = '.menuall > tbody:nth-child(1) > tr:nth-child(15) > td:nth-child(1) > img:nth-child(1)'
driver.find_element_by_css_selector(sysset_css2).click()
dalei_css = '#g_7 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
driver.find_element_by_css_selector(dalei_css).click()
sleep(2)
driver.switch_to.default_content()
driver.switch_to.frame('right')
sleep(2)
insertdl_css = 'input.button:nth-child(1)'
driver.find_element_by_css_selector(insertdl_css).click()
sleep(2)
driver.find_element_by_name("bigclass").send_keys("利润")
driver.find_element_by_name('submit').click()
sleep(2)
driver.switch_to.alert.accept()
sleep(2)

#新增一个小类
driver.switch_to.default_content()
driver.switch_to.frame('left')
xiaolei_css = '#g_7 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
driver.find_element_by_css_selector(xiaolei_css).click()
sleep(2)
driver.switch_to.default_content()
driver.switch_to.frame('right')
sleep(2)
insertxl_css = 'input.button:nth-child(1)'
driver.find_element_by_css_selector(insertxl_css).click()
sleep(2)
driver.find_element_by_name("smallclass").send_keys("利润1")
driver.find_element_by_name('submit').click()
sleep(2)
driver.switch_to.alert.accept()
sleep(2)

#退出系统，关闭浏览器
driver.switch_to.default_content()
driver.switch_to.frame('topFrame')
driver.find_element_by_link_text('安全退出').click()
sleep(2)
driver.switch_to.alert.accept()
sleep(2)
driver.quit()
